<!DOCTYPE html>
<html style="background: #e8e8e8">
<head lang="en">
    <meta charset="UTF-8">
    <meta name='apple-touch-fullscreen' content='yes'>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta content="fullscreen=yes,preventMove=no" name="ML-Config">
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no,email=no,address=no" />
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <link rel="stylesheet" href="/style/css/style.css"/>
    <script src="/style/js/index.js"></script>
    <script src="/style/js/jquery-1.12.0.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div class="header-reg">
    <img src="/style/images/login/logo.png" alt=""/>
    <h3>为了您的账号安全请绑定手机号码</h3>
</div>
<div class="section-reg">
    <dl>
        <dd>
            <i>手机号码</i>
            <input name="mobile" id="mobile" type="text" placeholder="请填写11位手机号码">
        </dd>
        <dd>
            <i>验证码</i>
            <input class="btnL" maxlength="6" id="check_code" type="text" placeholder="请填写短信验证码">
            <a href="javascript:_getsmscode();" class="button btn-huoqu">
                获取
            </a>
        </dd>
        <dd>
            <i>姓名</i>
            <input name="name" id="name" type="text" placeholder="请填写姓名">
        </dd>
        <dd>
            <i>邀请码</i>
            <input name="recode" type="text" id="recode" placeholder="请填写邀请码或使用默认邀请码">
        </dd>
        <dt>
            <input type="checkbox" id="agreen">
            <p>本人已阅读并同意《 <a href="/user/xieyi">西海良品服务规则&服务协议</a>》</p>
            <!--<input name="" type="image" onclick="tj()" src="/images/submit_btn.png">-->
        </dt>
    </dl>
</div>
<div class="footer-reg">
    <!-- <p>填写有效的邀请码可获赠4张免邮券</p> -->
    <div id="sub_btn">注册</div>
    <a href="/passport/signin">已有账号，马上登录</a>
</div>
</body>
<script type="text/javascript" src="/style/js/sweet-alert.min.js"></script>
<link type="text/css" rel="stylesheet" href="/style/css/sweet-alert.css">
<script>
$(document).ready(function() {
    $("#sub_btn").click(function() {

     
          if ($("#mobile").val() == "") {
            swal("手机号码不能为空");
            return false;
          }
          
          if ($("#check_code").val() == "") {
              swal("请填写短信验证码");
              return false;
          }

          if ($("#name").val() == "" && _a!="") {
              swal("请填写姓名");
              return false;
          }

          if($("#recode").val() == "" && _a!=""){
        	 
        	  swal("请填写邀请码");
              return false;
              }
          if(!$('#agreen').prop('checked'))
          {
              swal("认真阅读并同意协议才能注册");
              return false;
          }      
         
          $.post("ajax", {
              "act": "reg",
              "mobile": $("#mobile").prop("value"),
              "smscode": $("#check_code").prop("value"),
              "recode":$("#recode").prop("value"),
              "name":$("#name").prop("value"),
              "mr": Math.random()
          }, function(data) {
              if (data.code == 200) {
                  swal("注册成功！", false, "success");
                  setTimeout(function() {
                      
                    window.location.href = "signin";
                         
                  }, 2100);
              } else if (data.code == 901) {
                  swal("验证码错误", false, "error");
              } else if (data.code == 902) {
                  swal("手机号码格式不正确", false, "error");
              } else if (data.code == 903) {
                  swal("手机号码已存在", false, "error");
              } else if (data.code == 904) {
                  swal("优惠券发放失败", false, "error");
              } else if (data.code == 905) {
                  swal("邀请码无效", false, "error");
              }else if (data.code == 906) {
                  swal("邀请码不能为空", false, "error");
              }
              
          }, 'json');
    

        
    });
});
   var _smscodeStat = false,
    _smscodeSec = 60,
    parm = /^(13|14|15|16|17|18|19)+([0-9]{9})$/;

function _smscodeTimer() {
    if (_smscodeStat && _smscodeSec > 0) {
        $(".btn-huoqu").html(_smscodeSec + '秒后重发');
        _smscodeSec -= 1;
        setTimeout("_smscodeTimer();", 1000);
    } else {
        _smscodeStat = false;
        _smscodeSec = 60;
        $(".btn-huoqu").html('获取');
    }
}

function _getsmscode() {
    if (!_smscodeStat) {
        var _do = true;
        if ($("#mobile").prop("value") == "") {
            swal("请填写手机号码");
            _do = false;
        } else if (!parm.test($("#mobile").prop("value"))) {
            swal("手机号码格式不正确");
            _do = false;
        }
        if (_do) {
            $.post("ajax", {
                "act": "sendsmscode",
                "mobile": $("#mobile").prop("value"),
                "type": 'reg',
                "mr": Math.random()
            }, function(msg) {
                console.log(msg);
                if (msg.code == 200) {
                    _smscodeStat = true;
                    _smscodeTimer();
                    swal("验证码已发送!");
                } else if (msg.code == 404) {
                    swal("手机号码已被注册");
                } else if (msg.code == 403) {
                    swal("保存验证码失败");
                } else if (msg.code == 409) {
                    swal("验证码发送失败");
                } else if (msg.code == 900) {
                    swal("手机号码错误");
                } else {
                    swal("发送验证码失败");
                }
            },"json");
        }
    }
}
</script>
</html>